package com.thread;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author: mayu
 * @date: 2021年04月09日 11:02
 */
public class TestLockSupport {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                if (i==5) {
                    LockSupport.park();
                }
                System.out.println(i);
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        LockSupport.unpark(t);

        //try {
        //    TimeUnit.SECONDS.sleep(8);
        //} catch (InterruptedException e) {
        //    e.printStackTrace();
        //}
        //LockSupport.unpark(t);
    }
}
